﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections;
using System.Collections.Generic;
using FoundationLib.AddIns.Constraints;

namespace FoundationLib.AddIns.Constrains.Test
{
	[TestClass]
	public class TestOclTransformer
	{
		[TestMethod]
		public void TestExpressions()
		{
			SortedList<int, TestTuple> tuples = TestDataFactory.CreateTestData();
			foreach (var item in tuples)
			{
				MethodOclStatement stmt = new MethodOclStatement(item.Value.Input, null, MethodConstraintType.PreCondition,
					item.Value.ReturnTypeName, item.Value.ReturnIsArray);
				OclTransformer transformer = new OclTransformer(new List<OclStatement> { stmt });
				IEnumerable<string> result = transformer.Transform();

				Assert.IsNotNull(result);
				Assert.IsTrue(result.Count() == 1);
				Assert.AreEqual("Contract.Requires(" + item.Value.Expected + ");",
 					result.First(),
					String.Format("Item {0} is invalid.", item.Key));
			}
		}
	}
}
